﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst.Context;

using DevWeb.Biztalk.DeploymentSettings.WebUI.Bootstrapper;
using DevWeb.Biztalk.DeploymentSettings.WebUI.Elmah;
using Microsoft.Ajax.Utilities;
using Microsoft.Practices.Unity;

namespace DevWeb.Biztalk.DeploymentSettings.WebUI.Controllers
{

  //  [ElmahHandleError]
    public class BaseController : Controller
    {

       [Dependency]
        public IDatabaseContext Context { get; set; }


        public BaseController()
        {

        }
        public BaseController(IDatabaseContext context)
        {
            Context = context;

            

            if (User.Identity.IsAuthenticated && (String.IsNullOrEmpty(Context.UserName)))
                context.UserName = System.Web.HttpContext.Current.User.Identity.Name;

            if (Context == null)
            {
                Context = new DeploymentSettingsContext();

                Context.UserName = System.Web.HttpContext.Current.User.Identity.Name;
            }

            if (String.IsNullOrEmpty(Context.UserName))
            {

                Context.UserName = System.Web.HttpContext.Current.User.Identity.Name;
            }

           
        }

        protected override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
        }
    }

  
}